package cn.bossfriday.im.common.rpc;

import cn.bossfriday.common.utils.GsonUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.StringJoiner;

/**
 * RpcMessageContext
 *
 * @author chenx
 */
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RpcMessageContext {

    private long appId;
    private String method;
    private String requesterId;
    private String targetId;

    private byte protocolVersion;
    private int qosFlags;
    private String apiVersion;

    private String channelId;
    private int requestMessageId;
    private String msgId = "";

    private String clientOs;
    private String deviceId;
    private String sdkVersion;
    private int connectedTerminalCount;
    private String userId;
    private String userName;
    private String clientAddr;
    private String appPackageName;

    private int resultCode;
    private String logId;
    private long sendTime = 0;
    private String messageClass;

    /**
     * getRouteResourceId
     *
     * @param appId
     * @param targetResourceId
     * @return
     */
    public static String getRouteResourceId(long appId, String targetResourceId) {
        return new StringJoiner("@")
                .add(String.valueOf(appId))
                .add(targetResourceId)
                .toString();
    }

    @Override
    public String toString() {
        return GsonUtil.toJson(this);
    }
}
